import type {Action} from "redux";
import { userReducer,UserAction,UserInfo } from "./user";


interface InitState {
    breadcrumb:{title:string}[] //面包屑
    theme:string //主题 白天 夜间
    isThemeColor:string //主题颜色
    menuBgColor:string //菜单背景颜色
    userInfo:UserInfo | null
}
const initState:InitState = {
    breadcrumb: [],
    theme: "light",
    isThemeColor: "#fff",
    menuBgColor: "#508EF5",
    userInfo: null
}

//当store调用dispatch的时候，就会走一遍reducer方法
export const reducer = (state = initState,action:Action | UserAction) => {
    switch (action.type) {
        case "set_breadcrumb":
            //这里可以对数据进行处理，例如更新state中的属性，最终返回新的数据，返回数据后，调用store.getState()就可以获取最新数据了
            return {...state,...action}
        case "set_theme":
            return {...state,...action}
        case "set_isThemeColor":
            return {...state,...action}
        case "set_userInfo":
            return {...state,...action}
        default:
            return state
    }
}

